/********************************************************************************
 *      Copyright:  (C) 2025 LingYun IoT System Studio
 *                  All rights reserved.
 *
 *       Filename:  database.h
 *    Description:  This file 
 *
 *        Version:  1.0.0(25/03/25)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "25/03/25 14:15:11"
 *                 
 ********************************************************************************/
#ifndef _DATABASE_H_
#define _DATABASE_H_

#include <sqlite3.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "logger.h"
#include "struct.h"

#define TABLENAME "server_table"

/*打开，创建数据库和表*/
int database_init(const char *db);

/*关闭数据库*/
void database_term(void);

/*插入数据 */
int database_insert(data_t *data);

/*插入前检查唯一性*/
int database_safe_insert(socket_ser *sock, data_t *data);

/*查一条数据发生并删除*/
int database_check_write_delete(socket_ser *sock, data_t *data);

#endif

